%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fresnel formulae.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;

n1 =1;					n2 =1.5;
tht0=[0:.01:pi/2];
thtt=asin(n1/n2*sin(tht0));
alf=sqrt(1-sin(thtt).^2)./cos(tht0);
bet=n2/n1;

Er_p=(alf-bet)./(alf+bet);              %p-polarization
Et_p=2./(alf+bet);
Ir_p=((alf-bet)./(alf+bet)).^2;
It_p=alf.*bet.*(2./(alf+bet)).^2;

Er_s=-(1-alf.*bet)./(1+alf.*bet);       %s-polarization
Et_s=sqrt(alf.*bet)./(1+alf.*bet);
Ir_s=((1-alf.*bet)./(1+alf.*bet)).^2;
It_s=alf.*bet.*(2./(1+alf.*bet)).^2;

figure(1);				clf;
subplot(221),plot(tht0/pi*180,Er_p,'r',tht0/pi*180,Et_p,'b',...
    tht0/pi*180,abs(Er_s),'-.r',tht0/pi*180,abs(Et_s),'-.b','LineWidth',1.4)
hold on;
subplot(221),plot([0 90],[0 0],'-.k',[57 57],[-.2 0],'-.k','LineWidth',1)
set(gca,'xLim',[0 90],'yLim',[-.2 1],'FontSize',16,'LineWidth',1.4)
xlabel('\fontsize{16}{\it\theta}_0');
ylabel('\fontsize{16}{\itE_r}/{\itE}_0   ,   {\itE_t}/{\itE}_0');
grid;
subplot(222),plot(tht0/pi*180,Ir_p,'r',tht0/pi*180,It_p,'b',...
    tht0/pi*180,Ir_s,'-.r',tht0/pi*180,It_s,'-.b','LineWidth',1.4)
hold on;
subplot(222),plot([0 90],[0 0],'-.k',[57 57],[0 1],'-.k','LineWidth',1)
set(gca,'xLim',[0 90],'yLim',[0 1],'FontSize',16,'LineWidth',1.4)
xlabel('\fontsize{16}{\it\theta}_0');
ylabel('\fontsize{16}{\itI_r}/{\itI}_0   ,   {\itI_t}/{\itI}_0');
grid;


% alternative

af1=[0:.01:pi/2];		af2=asin(n1/n2*sin(af1));

r_p=tan(af1-af2)./tan(af1+af2);
r_s=sin(af1-af2)./sin(af1+af2);
rr_p=(n2*cos(af1)-n1*cos(af2))./(n2*cos(af1)+n1*cos(af2));
rr_s=(n1*cos(af1)-n2*cos(af2))./(n1*cos(af1)+n2*cos(af2));

subplot(223),plot(af1/pi*180,abs(r_p).^2,'r',af1/pi*180,1-abs(r_p).^2,'b',...
    af1/pi*180,abs(r_s).^2,'-.r',af1/pi*180,1-abs(r_s).^2,'-.b','LineWidth',1.4)
set(gca,'xLim',[0 90],'yLim',[0 1],'FontSize',16,'LineWidth',1.4)
xlabel('\fontsize{16}{\it\theta}_0');
ylabel('\fontsize{16}{\itI_r}/{\itI}_0   ,   {\itI_t}/{\itI}_0');
grid;
